home *** CD-ROM | disk | FTP | other *** search
- { *****************************************************
- THookedLabel Component
-
- A trivial example of a component which hooks an event from
- a TEventList.
-
- Paul Warren
- HomeGrown Software Development
- (c) 1997 Langley British Columbia.
- (604) 856-6523
- e-mail: hg_soft@uniserve.com
- Home page: http://users.uniserve.com/~hg_soft
- ***************************************************** }
-
- unit Hooklbl;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, HookdBtn;
-
- type
- TMessageKind = (mkDate, mkTime, mkUpbeat);
-
- THookLabel = class(TLabel)
- private
- { private declarations }
- FMessageKind: TMessageKind;
- FSource: THookedButton;
- procedure SetSource(Value: THookedButton);
- protected
- { protected declarations }
- public
- { public declarations }
- constructor Create(AOwner: TComponent); override;
- procedure UpdateLabel(Sender: TObject);
- published
- { published declarations }
- property MessageKind: TMessageKind read FMessageKind write FMessageKind;
- property Source: THookedButton read FSource write SetSource;
- end;
-
- procedure Register;
-
- implementation
-
- constructor THookLabel.Create(AOwner: TComponent);
- var
- i: integer;
- begin
- inherited Create(AOwner);
- for i := 0 to TForm(AOwner).ComponentCount-1 do
- begin
- if TForm(AOwner).Components[i] is THookedButton then
- begin
- FSource := THookedButton(TForm(AOwner).Components[i]);
- Break;
- end;
- end;
- end;
-
- procedure THookLabel.UpdateLabel(Sender: TObject);
- begin
- case MessageKind of
- mkDate: Caption := DateToStr(Date);
- mkTime: Caption := TimeToStr(Time);
- mkUpbeat: Caption := 'What a wonderful day';
- end;
- end;
-
- procedure THookLabel.SetSource(Value: THookedButton);
- begin
- FSource := Value;
- { if successful hook HookEvent }
- if (FSource <> nil) then
- FSource.HookEvent := UpdateLabel;
- end;
-
- { register component on Samples page }
- procedure Register;
- begin
- RegisterComponents('Samples', [THookLabel]);
- end;
-
- end.